﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
using IPTV.DBUtility;
using IPTV.module;
using System.Data;

/// <summary>
/// Summary description for PlateDao
/// </summary>
namespace IPTV.dao
{
    public class CourseDao
    {
        public CourseDao()
        {
            
        }

        public CourseDto findCourseById(string courseId)
        {

            string sql = " SELECT c.video_id  , c.teacher_id ,  c.cat_id   , c.video_name , c.video_length , c.video_url , "
            + " c.shot_time , c.status , c.keyword , c.remark , c.post_date , c.rank , c.comment_count , c.scoring_count , c.averagescore , "
            + " c.browser_count , c.isrecommend , c.small_url , c.video_type , c.level , c.cat_name , c.user_id , c.file_size , c.video_hd_url , "
            + " c.video_common_url , c.front_photo ,c.big_url , c.tagIDs , c.re_sort , c.code , c.video_hits , c.picOne ,c.picTwo , c.grade , c.subject , "
            + " c.scope , c.scopename , c.allcategoryid , c.isbest , c.coin , c.poststatus , g.name "
            + " FROM cms_video_ext c , grade g"
            + " WHERE c.poststatus = 1  AND c.video_id = @courseId AND g.id = c.grade";
           
            MySqlParameter[] parms = new MySqlParameter[] 
                { 
                    new MySqlParameter( "@courseId" , MySqlDbType.VarChar, 50 )
                };

            parms[0].Value = courseId;
            CourseDto course = null;
            try
            {
                MySqlDataReader reader = MySQLHelper.ExecuteReader(MySQLHelper.CONNECTION_STRING, sql, parms);

                while (reader.Read())
                {
                    course = new CourseDto();
                    course.VideoId = reader[0].ToString();
                    course.TeacherId = reader[1].ToString();
                    course.CatId = reader[2].ToString();
                    course.VideoName = reader[3].ToString();
                    course.VideoLength = reader[4].ToString();
                    course.VideoUrl = reader[5].ToString();
                    course.ShotTime = reader[6].ToString();
                    course.Status = reader[7].ToString();
                    course.Keyword = reader[8].ToString();
                    course.Remark = reader[9].ToString();
                    course.PostDate = reader[10].ToString();
                    course.Rank = Convert.ToInt32(reader[11].ToString());
                    course.CommentCount = Convert.ToInt32(reader[12].ToString());
                    course.ScoringCount = Convert.ToInt32(reader[13].ToString());
                    course.Averagescore = Convert.ToDecimal(reader[14].ToString());
                    course.BrowserCount = Convert.ToInt32(reader[15].ToString());
                    course.IsRecommend = reader[16].ToString();
                    course.SmallUrl = reader[17].ToString();
                    course.VideoType = reader[18].ToString();
                    course.Level = reader[19].ToString();
                    course.CatName = reader[20].ToString();
                    course.UserId =  Convert.ToInt32(reader[21].ToString());
                    course.File_size =  Convert.ToInt32(reader[22].ToString());
                    course.VideoHdUrl = reader[23].ToString();
                    course.VideoCommonUrl = reader[24].ToString();
                    course.FrontPhoto = reader[25].ToString();
                    course.BigUrl = reader[26].ToString();
                    course.TagIDs = reader[27].ToString();
                    course.ReSort =  reader[28].ToString();
                    course.Code = reader[29].ToString();
                    course.VideoHits = reader[30].ToString();
                    course.PicOne = reader[31].ToString();
                    course.PicTwo = reader[32].ToString();
                    course.GradeId = reader[33].ToString();
                    course.SubjectId = reader[34].ToString();
                    course.Scope = reader[35].ToString();
                    course.Scopename = reader[36].ToString();
                    course.AllCategoryID = reader[37].ToString();
                    course.Isbest = reader[38].ToString();
                    course.Coin =  Convert.ToDecimal(reader[39].ToString());
                    course.Poststatus =  reader[40].ToString();
                    course.GradeName = reader[41].ToString();

     
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("findCourseById run error." + e.Message);
            }

            return course;

        }
    }
}